Repository navigation
feat(io): add duplex forwarding for BufReader/BufWriter and optimize repeat::read_vectored - #695
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds duplex forwarding capabilities to BufReader and BufWriter, allowing them to forward complementary I/O operations to their inner types when those types support them. This addresses issue #691 by enabling BufReader to implement AsyncWrite (when the inner type supports it) and BufWriter to implement AsyncRead/AsyncBufRead (when the inner type supports them). The implementation follows tokio's design philosophy: BufReader retains its read buffer when writing, and BufWriter does not implicitly flush when reading. Additionally, this PR optimizes repeat::read_vectored with a dedicated implementation.
Changes:
- Added
AsyncWritetrait implementation forBufReader<R>whenR: AsyncRead + AsyncWrite - Added
AsyncReadandAsyncBufReadtrait implementations forBufWriter<W>when the inner type supports them - Implemented optimized
read_vectoredforRepeatto efficiently fill vectored buffers
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| compio-io/src/read/buf.rs | Added AsyncWrite trait forwarding for BufReader when inner type supports it |
| compio-io/src/write/buf.rs | Added AsyncRead and AsyncBufRead trait forwarding for BufWriter when inner type supports them |
| compio-io/src/util/repeat.rs | Added optimized read_vectored implementation for Repeat type |
| compio-io/tests/io.rs | Added comprehensive tests for duplex forwarding behavior and repeat_read_vectored |
| compio-io/CHANGELOG.md | Documented new trait implementations in unreleased section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
LGTM. Feel free to determine whether to edit the change log. Actually it's generated by release-plz.
EDIT: @George-Miao requires removing them:)
It is worth noting that the current implementation retains the read buffer when writing with BufReader, and does not implicitly flush the write buffer when reading with BufWriter. These behaviors are aligned with the tokio design.
Closes #691